home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: String Problem
- Date: 25 Mar 1996 15:21:41 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4j79q5INNt27@keats.ugrad.cs.ubc.ca>
- References: <4j6l61$4no@B1FF.mindspring.com> <Pine.A32.3.91.960325141646.16066F-100000@red.weeg.uiowa.edu>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <Pine.A32.3.91.960325141646.16066F-100000@red.weeg.uiowa.edu>,
- The Amorphous Mass <robinson@blue.weeg.uiowa.edu> wrote:
- >On Mon, 25 Mar 1996, Shon Frazier wrote:
- >
- >> This is supposed to be a variation on sample code from a textbook.
- >> Can anyone tell me why NameCheck = 0 when I run the program?
- >
- > You can't compare strings with == (the code with compare the
- >values of the pointers to those strings, which is an altogether different
- >matter). You need to use the standard library function strcmp() (in
- ><string.h>) which returns 0 if the strings are equal.
- >
- > int strcmp(const char *s1, const char *s2);
- >
- > Strings are not a basic data type in C, so it is generally true that if
- >you need to do something to a string, you pass it to a function. :-)
-
- Nevertheless, the ANSI standard blesses the standard library functions as
- special, in effect raising them to the status of operators of the language.
- Compilers have the license (in a hosted implementation) to turn strcmp() into
- inline code, and many compilers, including GCC, take advantage of this.
-
- In essence, strcmp(string1,string2) becomes a syntactic variant of something
- like (string1 != string2), barring the three-way result semantics.
-
- You can still think of strcmp() as being a function, of course. The standard
- guarantees that you can take the address of any standard library
- function, so that you can pass a pointer to strcmp to a sorting function like
- qsort(). This is very nice compared to languages like Pascal whose built-in
- operators like writeln() can't be, for the most part, written in the language
- itself.
- --
-
-